home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
C64
/
H-Graphics
/
(c)h6.d64
/
hrsupp.src.c
< prev
next >
Wrap
C/C++ Source or Header
|
2007-02-04
|
9KB
|
551 lines
.OPT NOL
;
;** HRSUPP/64 **
;
ORIGIN = $6000
;
;** EQUATES **
;
;SYSTEM ROUTINES
;
ERROR = $A437 ;PRINT ERROR MESSAGE
EVAEXP = $AD9E ;EVALUATE EXPRESSION
CHKCOM = $AEFD ;CHECK FOR COMMA
FLTFIX = $B1AA ;CONVERT TO FIXED IN Y (LOW) AND A (HIGH)
;
;VECTORS
;
ERRVEC = $0300 ;ERROR ROUTINE
WARMV = $0302 ;BASIC WARM START
;
;HI-RES STUFF
;
VIC = $D000 ;ADDRESS OF VIC CHIP
HRCTRL = VIC+17 ;MODE CONTROL
HRMREG = VIC+24 ;MEMORY CONTROL
;
SCREEN = $0400 ;1K SCREEN
SCREND = SCREEN+999 ;LAST SCREEN LOC'N
BASE = $2000 ;START OF 8K BYT
HRLAST = BASE+7999 ;LAST LOC'N
RAM = $033C ;USE CASSETTE BUFFER
;
;**ZERO PAGE**
;
BYT = $FD ;BYT POINTER
;
*=RAM
;
X1 *=*+2 ;X COORDINATE (0 - 319)
X2 *=*+2
Y1 *=*+2 ;Y COORDINATE (0 - 199)
Y2 *=*+2
BITNO *=*+1 ;ON BIT IS PIXEL
DELTX *=*+2 ;X2-X1
DELTY *=*+2 ;Y2-Y1
E *=*+2
T *=*+2
C *=*+2
I *=*+1 ;DIRECTION POINTER
TEMP *=*+2
ERVEC *=*+2 ;HOLDS SYSTEM ERROR VECTOR
;
;CONSTANTS
;
XMAX=320
YMAX=200
COLS=40 ;NUMBER OF COLUMNS/ROW
COLOR=$50 ;FOREGROUND/BACKGROUND = BLACK/GREEN
;
*=ORIGIN
;
;JUMP TABLE FOR COVENIENT ENTRY POINTS
;
JINIT JMP HRINIT ;INITIALIZE
JREST JMP HRREST ;RESTORE
JCLR JMP CLRHR ;CLEAR SCREEN
JDRAW JMP VECPLT ;DRAW STRAIGHT LINE
JSETPX JMP SETPIX ;TURN ON PIXEL
;
;FALL THROUGH TO MOVE ROUTINE
;
;HRADDR - GIVEN X-COORD (2 BYTES)
;AND Y-COORD (1 BYTE)
;CALCULATE BYT ADDRESS AND BITNO
;
;CLOBBERS X, LEAVES Y=0
;
;ENTER HERE IF FROM BASIC
;
HRMOVE JSR GETVAL ;GET X1
STY X1
STY X2 ;FOR RNGCHK
STA X1+1
STA X2+1
JSR GETVAL ;GET Y1
STY Y1
STY Y2
STA Y2+1
JSR RNGCHK
;
;ENTER HERE IF X1, Y1 ARE SET
;
HRADDR LDA #0 ;SET HIGH BYTE TO ZERO
STA BYT+1
SEC ;FORM 199-Y1
LDA #YMAX-1
SBC Y1
PHA ;SAVE RESULT ON STACK
AND #$F8 ;FORM ROW #
ASL A ;MULT BY 2
ROL BYT+1
ASL A ;MULT BY 4
ROL BYT+1
ASL A ;MULT BY 8
ROL BYT+1
PHA ;SAVE ON STACK
STA TEMP ;AND IN TEMP
LDA BYT+1
STA TEMP+1 ;TEMP HAS 8*Y
PLA ;RESTORE A
ASL A ;MULT BY 16
ROL BYT+1
ASL A ;MULT BY 32
ROL BYT+1 ;(CARRY STILL CLEAR)
ADC TEMP ;FORM 32+8 = 40*
STA BYT ;INTO BYT
LDA BYT+1
ADC TEMP+1
STA BYT+1
LDA X1 ;NOW ADD CHAR
AND #$F8
ADC BYT
STA BYT
LDA X1+1
ADC BYT+1
STA BYT+1 ;(CARRY STILL CLEAR)
PLA ;NOW ADD LINE
AND #7 ;BY MASKING HIGH BITS
ADC BYT
STA BYT
LDA BYT+1 ;FINISH BY ADDING BASE
ADC #>BASE
STA BYT+1
LDA X1 ;SET BITNO
AND #7 ;IS LOW 3 BITS
TAX ;AND INDEX TO TABLE
LDA MSKTB,X
STA BITNO
RTS ;BYT AND BITNO NOW SET
;
;*** FASTPLOT ***
;
;GRAPHIC SUBROUTINE FOR LINE DRAWING
;ON 320*200 HI-RES MEMORY
;
;ORIGINALLY WRITTEN AS VECTOR GENERATOR
;FOR HOUSTON INSTRUMENT HIPLOT
;DIGITAL INCREMENTAL PLOTTER
;
;MORE EFFICIENT ALGORITHM BY W. MCWORTER
;IN BYTE MAY 1981, P202
;
;RE-WRITTEN FOR MTU VISIBLE MEMORY (TM)
;BY F. COVITZ, AUG. 1981
;REVISED NOV. 1982 FOR CBM-64
;
;
;*****************************
;* TYPO IN ORIGINAL LETTER *
;* *
;* IT READS; A$="RQVWPS...." *
;* * *
;*SHOULD BE; A$="RQVWRS...." *
;* *
;*****************************
;
;COME IN WITH X1,Y1 AND X2,Y2
;AND FIRST PIXEL SET
;I.E. BYT,BYT+1, AND BITNO ARE SET
;VIA CALL TO PIXADR
;ROUTINE DRAWS BEST STRAIGHT LINE
;LEAVES WITH X1_X2,Y1_Y2
;
;LEAVES WITH Y=0, X CLOBBERED
;ROUTINE CHECKS FOR OVERFLOW
;
;**VECPLT**
;
;ENTER HERE FROM BASIC
;
VECPLT JSR GETVAL ;GET X-COORD
STY X2
STA X2+1
JSR GETVAL ;GET Y-COORD
STY Y2
STA Y2+1
;
;ENTER HERE IF X2, Y2 ALREADY SET
;
VECPL1 JSR RNGCHK ;CHECK X2,Y2 OVERFLOW
SEC ;FORM DELTX (SIGNED)
LDA X2
SBC X1
STA DELTX
LDA X2+1
SBC X1+1
STA DELTX+1
SEC ;FORM DELTY (SIGNED)
LDA Y2
SBC Y1
STA DELTY
LDA Y2+1
SBC Y1+1
;
STA DELTY+1
LDA X2 ;X1,Y1_X2,Y2
STA X1
LDA X2+1
STA X1+1
LDA Y2
STA Y1
LDA Y2+1
STA Y1+1
;
;NOW HAVE DELTX,DELTY (SIGNED)
;
;** MOVE **
;
;GIVEN DELTX, DELTY
;DRAW/MOVE THE BEST STRAIGHT LINE
;
MOVE LDA #0 ;DETERMINE OCTANT
STA I
BIT DELTX+1 ;CHECK DELTX < 0
BPL MV1
LDA DELTX ;CHANGE SIGN
JSR COMPL
STA DELTX
LDA DELTX+1
JSR COMPH
STA DELTX+1
LDA #2
STA I
MV1 BIT DELTY+1 ;CHECK DELTY < 0
BPL MV2
LDA DELTY
JSR COMPL
STA DELTY
LDA DELTY+1
JSR COMPH
STA DELTY+1
CLC
LDA I
ADC #4
STA I
MV2 LDX DELTX ;CHECK DELTX-DELTY
CPX DELTY ;SET CARRY FOR LOW BYTE
LDA DELTX+1 ;NOW HIGH BYTE
TAY ;SET Y = DELTX
SBC DELTY+1
BPL MV3
LDA DELTY ;INTERCHANGE DELTX,Y
STA DELTX
LDA DELTY+1
STA DELTX+1
STX DELTY
STY DELTY+1
CLC
LDA I
ADC #8
STA I
MV3 LDA DELTX ;FORM E=-DELTX/2
JSR COMPL
STA E
LDA DELTX+1
JSR COMPH
STA E+1
SEC ;CHECK FOR NEGATIVE
BMI MV4
CLC
MV4 ROR E+1 ;DIVIDE BY 2
ROR E
LDY #0 ;SET Y=0
STY C ;SET COUNTER TO ZERO
STY C+1
BEQ MV7 ;ABSOLUTE BRANCH
;
;** MAIN DRAWING LOOP **
;
MV5 LDX I ;GET DIRECTION IN X
CLC ;FORM E=E+DELTY
LDA E
ADC DELTY
STA E ;FIRST LOW BYTE
LDA E+1
ADC DELTY+1
STA E+1
BMI MV6
SEC ;FORM E=E-DELTX
LDA E
SBC DELTX
STA E
LDA E+1
SBC DELTX+1
STA E+1
INX ;X BUMPED UP ONE
MV6 JSR OUTPLT ;OUTPUT ONE MOVE
INC C ;BUMP COUNTER UP 1
BNE MV7
INC C+1
;
;ENTER HERE ON 1ST PASS
;
MV7 LDA (BYT),Y ;TURN ON A POINT
ORA BITNO
STA (BYT),Y
LDA C ;DONE WHEN C > = DELTX
CMP DELTX
LDA C+1
SBC DELTX+1
BCC MV5
RTS ;DONE
;
;** OUTPLT **
;
;OUTPUT AN ELEMENTARY MOVE
;
OUTPLT TXA
ASL A ;MULT BY TWO TO GET INDEX
TAX
LDA MOVTAB+1,X ;GET THE VECTOR
PHA ;HIGH BYTE ON STACK
LDA MOVTAB,X
PHA ;LOW BYTE ON STACK
RTS ;DO COMPUTED JUMP
;
;RETURN VIA RTS TO JSR OUTPLT(1)
;
;**RNGCHK**
;
;CHECK X2, Y2 FOR OVERFLOW
;RETURN TO CALLING PROGRAM ON OVERFLOW
;
RNGCHK LDA X2 ;CHECK X2, LOW
CMP #<XMAX
LDA X2+1 ;CHECK HIGH BYTE
SBC #>XMAX
BCS RNG2 ;X2 > XMAX, SO ABORT
RNG1 LDA Y2 ;CHECK Y2, LOW
CMP #<YMAX
LDA Y2+1 ;CHECK HIGH BYTE
SBC #>YMAX
BCC RNG3 ;Y2 < YMAX, SO OK
RNG2 JSR HRREST ;RESTORE NORMAL
LDX #14 ;ILLEGAL QUANTITY ERROR
JMP (ERRVEC) ;FUNNEL THROUGH ERROR ROUTINE
RNG3 RTS
;
;COMPL,H
;
;FORM COMPLEMENT OF SIGNED NUMBER
;1ST ENTER AT COMPL FOR LOW BYTE
;THEN ENTER AT COMPH FOR HIGH BYTE
;
;ANSWER IN A
;
COMPL SEC ;FOR LOW BYTE
COMPH EOR #$FF ;COMPLEMENT
ADC #0 ;ADD CARRY STATE
RTS
;
LL JSR LEFT ;GO LEFT AND FALL THROUGH TO DOWN
DOWN LDA BYT
AND #7 ;EXAM LOWEST 3 BITS
EOR #7 ;FLIP THEM
BEQ DN2 ;ORIGINAL BYTE WAS XXXX111
INC BYT ;ELSE JUST BUMP BY 1
BNE DN3
INC BYT+1
BNE DN3 ;BRANCH ALWAYS
DN2 CLC ;ADD 320-7
LDA BYT
ADC #<313
STA BYT
LDA BYT+1
ADC #>313
STA BYT+1
DN3 RTS
;
UR JSR RIGHT ;FIRST RIGHT THEN FALL THROUGH TO UP
UP LDA BYT
AND #7 ;CHECK LOW BITS
BNE UP1 ;IF BYTE WAS NOT XXXXX000
SEC ;ELSE SUBTRACT 320-7
LDA BYT
SBC #<313
STA BYT
LDA BYT+1
SBC #>313
STA BYT+1
BNE UP3 ;BRANCH ALWAYS
UP1 LDA BYT ;DECREMENT BY 1
BNE UP2
DEC BYT+1
UP2 DEC BYT
UP3 RTS
;
UL JSR UP ;1ST UP THEN FALL THROUGH TO LEFT
LEFT ASL BITNO ;GO 1 PIXEL LEFT
BCC LF2 ;NO CORRECTION ON CARRY CLEAR
ROL BITNO ;SET BITNO=1 AND CLEAR CARRY
LDA BYT
SBC #7 ;(-8 SINCE CARRY IS CLEAR)
STA BYT
BCS LF2
DEC BYT+1
LF2 RTS
;
LR JSR DOWN ;1ST DOWN THEN FALL THROUGH TO RIGHT
RIGHT LSR BITNO ;GO 1 PIXEL RIGHT
BCC RGT1
ROR BITNO ;SET BITNO=$80 AND CLEAR CARRY
LDA BYT
ADC #8 ;ONE CELL RIGHT
STA BYT
BCC RGT1
INC BYT+1
RGT1 RTS
;
;CLRHR
;
;CLEARS EXACTLY 8000 BYTES
;LEAVES Y=X=0
;
CLRHR LDA #>HRLAST
STA BYT+1 ;INIT. POINTER TO LAST PAGE
LDA #0
STA BYT
TAY
STA BYT
STA (BYT),Y ;THIS ONE DONE SEPARATELY
LDY #<HRLAST ;START AT BASE+$1F3F
LDX #$20 ;X KEEPS TRACK OF PAGES
CLRHR1 STA (BYT),Y ;PUT IN 0'S
DEY
BNE CLRHR1
DEC BYT+1
DEX
BNE CLRHR1 ;DO 32 PAGES
RTS
;
;SETCOL
;
;SET FOREGROUND/BACKGROUND COLOR
;
SETCOL LDA #COLOR ;IN 2 NYBBLES
SETCL0 LDX #0
SETCL1 STA SCREEN,X ;DO 4 PAGES
STA SCREEN+$0100,X
STA SCREEN+$0200,X
INX
BNE SETCL1
LDX #<SCREND+1 ;DO LAST PAGE
SETCL2 STA SCREEN+$02FF,X
DEX
BNE SETCL2
RTS
;
;HRINIT - SETS UP HI-RES
;
HRINIT LDA HRCTRL ;HI-RES MODE
ORA #$20 ;TURN ON BIT 5
STA HRCTRL
LDA HRMREG ;BYT AT $2000
ORA #$08 ;TURN ON BIT 3
STA HRMREG
JSR SETCOL ;FORCE BLACK AND GREEN
JSR CLRHR ;FORCE TO ALL ZEROES
LDA ERRVEC ;REMEMBER SYSTEM ERROR VECTOR
STA ERVEC
LDA ERRVEC+1
STA ERVEC+1
LDA #<ABRT ;SET UP NEW ERROR RECOVERY
STA ERRVEC
LDA #>ABRT
STA ERRVEC+1
RTS
;
;HRREST - RESTORE NORMAL MODE
;
HRREST JSR CLRHR ;CLEAR HI-RES
LDA HRCTRL ;MODE REGISTER
AND #%11011111 ;TURN OFF BIT 5
STA HRCTRL
LDA HRMREG ;MEMORY REGISTER
AND #%11110111 ;TURN OFF BIT 3
STA HRMREG
LDA #' ' ;FILL SCREEN WITH SPACES
JSR SETCL0
LDA ERVEC ;RESTORE SYSTEM ERROR VECTOR
STA ERRVEC
LDA ERVEC+1
STA ERRVEC+1
RTS
;
;GETVAL - GET PARAMETER
;
GETVAL JSR CHKCOM ;CHECK FOR COMMA
JSR EVAEXP ;EVALUATE EXPRESSION
JSR FLTFIX ;CONVERT TO INTEGER IN Y AND A
RTS
;
;ENTER HERE IF FROM BASIC
;
SETPIX JSR HRMOVE
;
;ENTER HERE IF X1,Y1 ALREADY SET
;
STPIX0 LDY #0
LDA (BYT),Y
ORA BITNO
STA (BYT),Y
RTS
;
;ERROR RECOVERY
;
ABRT PHA ;SAVE REGS
TXA
PHA
TYA
PHA
JSR HRREST ;RESTORE TO NORMAL
PLA ;RESTORE REGS
TAY
PLA
TAX
PLA
JMP (ERRVEC) ;ERROR MESSAGE
;
MOVTAB .WORD RIGHT-1
.WORD UR-1
.WORD LEFT-1
.WORD UL-1
.WORD RIGHT-1
.WORD LR-1
.WORD LEFT-1
.WORD LL-1
.WORD UP-1
.WORD UR-1
.WORD UP-1
.WORD UL-1
.WORD DOWN-1
.WORD LR-1
.WORD DOWN-1
.WORD LL-1
;
MSKTB .BYTE $80,$40,$20,$10
.BYTE $08,$04,$02,$01
;
.END